package com.dongnam.quanly.web.nghiepvu.quy.soquy;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.StreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.controller.SoQuyController;
import com.dongnam.quanly.common.model.SoQuy;
import com.dongnam.quanly.web.UserBean;
import com.dongnam.quanly.web.util.WebUtil;

@ManagedBean(name = "SoQuyBean")
@SessionScoped
public class SoQuyBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final Logger logger = LoggerFactory.getLogger(SoQuyBean.class);
	private UserBean userBean;

	private StreamedContent file;

	private boolean isEdit = false;

	private SoQuy soQuy;

	private SoQuy selectedSoQuy;

	private SoQuyController soQuyController;

	public UserBean getUserBean() {
		return userBean;
	}

	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}

	public StreamedContent getFile() {
		return file;
	}

	public void setFile(StreamedContent file) {
		this.file = file;
	}

	public boolean isEdit() {
		return isEdit;
	}

	public void setEdit(boolean isEdit) {
		this.isEdit = isEdit;
	}

	public SoQuy getSoQuy() {
		return soQuy;
	}

	public void setSoQuy(SoQuy soQuy) {
		this.soQuy = soQuy;
	}

	public SoQuy getSelectedSoQuy() {
		return selectedSoQuy;
	}

	public void setSelectedSoQuy(SoQuy selectedSoQuy) {
		this.selectedSoQuy = selectedSoQuy;
	}

	public SoQuyController getSoQuyController() {
		if (this.soQuyController == null) {
			this.soQuyController = new SoQuyController();
		}
		return this.soQuyController;
	}

	public void setSoQuyController(SoQuyController soQuyController) {
		this.soQuyController = soQuyController;
	}

	public SoQuyBean() {
		super();
		soQuy = new SoQuy();
		// TODO Auto-generated constructor stub
	}

	public void reloadPage() {
		WebUtil.redirect("/pages/nghiepvu/muabanhang/hoadon.xhtml");
	}

	public void handleFileUpload(FileUploadEvent even) {
		/**
		 * 
		 */
	}

	public void downloadFileCSV() {
		/**
		 * 
		 */
	}

	public void resetFormAdd() {
		soQuy = new SoQuy();
	}

	public void notifyAdd() {
		isEdit = false;
		resetFormAdd();
	}

	public void notifyEdit(SoQuy soQuy) {
		isEdit = true;
		this.selectedSoQuy = soQuy;
	}

	public void removeSoQuy() {

		if (this.selectedSoQuy != null) {
			getSoQuyController().makeTransient(this.selectedSoQuy);
		}

	}

	public void save() {
		/**
		 * 
		 */
	}

}
